#!/usr/bin/python3
# -*- coding: utf-8 -*-

import logging
from aiohttp import web
from view import ScriptView, BlogView, HlsView

routes = {}

modules = {'blog': BlogView(), 'script': ScriptView(), 'hls_': HlsView()}

for module_name, controller in modules.items():
    methods = [getattr(controller, item) for item in dir(controller) if not item.startswith(
        '__') and not item.startswith('_') and not item.endswith('__') and callable(getattr(controller, item))]
    route_ = []
    for method in methods:
        route = None
        if method.__name__ in controller.getPost():
            route = web.post(
                '/%s/%s' % (module_name, method.__name__), method)
        if method.__name__ in controller.getGet():
            route = web.get(
                '/%s/%s' % (module_name, method.__name__), method)
        if route:
            route_.append(route)
        if method.__name__ == 'items':
            route = web.get('/%s' % (module_name), method)
            route_.append(route)
        # print('%s --> %s, %s' %
        #         (module_name, method.__name__, type(method)))
    routes[module_name] = route_
